package com.xiaoze.question.controller;

import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xiaoze.common.annotation.Log;
import com.xiaoze.common.core.controller.BaseController;
import com.xiaoze.common.core.domain.AjaxResult;
import com.xiaoze.common.enums.BusinessType;
import com.xiaoze.question.domain.QuestionAnswer;
import com.xiaoze.question.service.IQuestionAnswerService;
import com.xiaoze.common.utils.poi.ExcelUtil;
import com.xiaoze.common.core.page.TableDataInfo;

/**
 * 试题题目选项管理Controller
 *
 * @author 胡昊泽
 * @date 2024-08-02
 */
@RestController
@RequestMapping("/question/answer" )
public class QuestionAnswerController extends BaseController {
    @Autowired
    private IQuestionAnswerService questionAnswerService;

    /**
     * 查询试题题目选项管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:answer:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(QuestionAnswer questionAnswer) {
        startPage();
        List<QuestionAnswer> list = questionAnswerService.selectQuestionAnswerList(questionAnswer);
        return getDataTable(list);
    }

    /**
     * 导出试题题目选项管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:answer:export')" )
    @Log(title = "试题题目选项管理" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(QuestionAnswer questionAnswer) {
        List<QuestionAnswer> list = questionAnswerService.selectQuestionAnswerList(questionAnswer);
        ExcelUtil<QuestionAnswer> util = new ExcelUtil<QuestionAnswer>(QuestionAnswer.class);
        return util.exportExcel(list, "answer" );
    }

    /**
     * 获取试题题目选项管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:answer:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(questionAnswerService.selectQuestionAnswerById(id));
    }

    /**
     * 新增试题题目选项管理
     */
    @PreAuthorize("@ss.hasPermi('question:answer:add')" )
    @Log(title = "试题题目选项管理" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionAnswer questionAnswer) {
        return toAjax(questionAnswerService.insertQuestionAnswer(questionAnswer));
    }

    /**
     * 修改试题题目选项管理
     */
    @PreAuthorize("@ss.hasPermi('question:answer:edit')" )
    @Log(title = "试题题目选项管理" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionAnswer questionAnswer) {
        return toAjax(questionAnswerService.updateQuestionAnswer(questionAnswer));
    }

    /**
     * 删除试题题目选项管理
     */
    @PreAuthorize("@ss.hasPermi('question:answer:remove')" )
    @Log(title = "试题题目选项管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(questionAnswerService.deleteQuestionAnswerByIds(ids));
    }
}
